import Toast from '../../component/vant/toast/toast';
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coach_list: [],
    domain: app.api.xh.downloadDomain
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var logging = wx.getStorageSync('_logining');

        if (!logging) {
            app.toAuth('/pages/my/my');
        } else {
          this.getCoach();
        }
    app.setPageTitle('我的辅导');

  },
  getCoach: function() {
    var page = this;
    //辅导列表
    var param = {
        type: 2
    };
    if (page.data.last_id != undefined && page.data.last_id != 0) {
        param.last_id = page.data.last_id;
    }
    app.sendRequest({
        data: param,
        url: app.api.coach.coach_student_list,
        success: function(res) {
            var coach_list = page.data.coach_list;
            var coach_list_load = res.data.list ? res.data.list : [];
            var last_id = 0;
            if (coach_list_load.length > 0) {
                last_id = res.data.last_id;
                coach_list = coach_list.concat(coach_list_load);
                page.setData({
                    coach_list: coach_list,
                    last_id: last_id
                });
            } else {
                page.data.coach_list.length > 0 && Toast('没有更多了');
            }
        }
    });
},

toCoach: function(e) {
  var cid = e.currentTarget.dataset.id;
  wx.navigateTo({
      url: '/pages/coach_result/coach_result?id=' + cid
  });
},

clearStorage: function() {
  var that = this;
  that.setData({
      loading: true,
      disabled: true
  });
  wx.clearStorage({
      success: function() {
          Toast('清除成功');
          that.setData({
              loading: false,
              disabled: false,
              toast1Hidden: false
          });
      }
  });
},

 

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },



   /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
      this.setData({
          last_id: 0,
          coach_list: []
      });
   
      this.getCoach();
      wx.stopPullDownRefresh();
  },

   /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
      this.getCoach();
      
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})